{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-04-24T07:51:59.474481Z",
     "start_time": "2025-04-24T07:51:59.246331Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "\n",
    "# Sigmoid函数，用于模拟神经元的激活函数\n",
    "def sigmoid(x):\n",
    "    return 1 / (1 + np.exp(-x))\n",
    "\n",
    "# 神经元模型\n",
    "class Neuron:\n",
    "    def __init__(self, inputs):\n",
    "        # 初始化权重和偏置，权重是随机小的数值，偏置初始化为0\n",
    "        self.weights = np.random.randn(inputs)\n",
    "        self.bias = 0\n",
    "    \n",
    "    def feedforward(self, inputs):\n",
    "        # 计算神经元的输出\n",
    "        total = np.dot(self.weights, inputs) + self.bias\n",
    "        return sigmoid(total)\n",
    "\n",
    "# 示例使用\n",
    "# 假设我们有一个具有3个输入的神经元\n",
    "neuron = Neuron(inputs=3)\n",
    "\n",
    "# 随机生成一些输入数据\n",
    "input_data = np.random.randn(3)\n",
    "\n",
    "# 计算神经元的输出\n",
    "output = neuron.feedforward(input_data)\n",
    "print(\"Neuron output:\", output)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neuron output: 0.3577272536401761\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-03T07:34:48.175729Z",
     "start_time": "2025-04-03T07:34:48.162091Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "e8cd634938fcb7d7",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-03T07:34:48.191047Z",
     "start_time": "2025-04-03T07:34:48.182558Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "e2ff1598d5925639",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
